package com.chuanyang.driverh.mainhome;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.bean.NoticeBean;


/**
 * Created by eason on 2017/2/15.
 */

public class CommonNoticeActivity extends Activity implements View.OnClickListener {


    private TextView tv_content;
    private TextView tv_cancle;
    private TextView tv_look;
    private RelativeLayout rl_out;
    private NoticeBean noticeBean;
    private int type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_act_notice);
        findView();

    }

    private void findView() {
        noticeBean = (NoticeBean) getIntent().getSerializableExtra("data");
//        rl_out = (RelativeLayout) findViewById(R.id.rl_outside);
        tv_content = (TextView) findViewById(R.id.tv_content);
        tv_cancle = (TextView) findViewById(R.id.tv_cancle);
        tv_look = (TextView) findViewById(R.id.tv_sure);
//        rl_out.setOnClickListener(this);
        tv_cancle.setOnClickListener(this);
        tv_look.setOnClickListener(this);
        fillView();

    }

    private void fillView() {
        tv_content.setText(noticeBean.getContent());
        tv_cancle.setText(noticeBean.getString1());
        tv_look.setText(noticeBean.getString2());
    }


    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case  R.id.tv_cancle:
                finish();
                break;
            case  R.id.tv_sure:
                enterOppositePager(noticeBean.getType());
                break;
//            case R.id.rl_outside:
//                finish();
//                break;
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);//如果不调用此方法，intent还会是之前的第一个intent
        noticeBean = (NoticeBean) getIntent().getSerializableExtra("data");
        fillView();
    }

    private void enterOppositePager(int type) {
        switch (type){
            case 4:
                Intent intent1 = new Intent(this, OrderDetailRceiveActivity.class);
                intent1.putExtra("data", noticeBean.getExtrainfo());
                startActivity(intent1);
                finish();
                break;
            case 5:
                Intent intent2 = new Intent(this, WaybilDetailDirverActivity.class);
                intent2.putExtra("waybilId", noticeBean.getExtrainfo());
                intent2.putExtra("type", 0);
                startActivity(intent2);
                finish();
                break;
            case 6:
                Intent intent3= new Intent(this, WaybilDetailActivity.class);
                intent3.putExtra("waybilId", noticeBean.getExtrainfo());
                startActivity(intent3);
                finish();
                break;
        }
    }


}
